<?php

class Util{

	public static function camelize($string, $pascalCase = true){ 
		$string = str_replace(array('-', '_'), ' ', $string); 
		$string = ucwords($string); 
		$string = str_replace(' ', '', $string);  
		if (!$pascalCase)
			return lcfirst($string); 
		return $string; 
	}

	public static function decamelize($string, $pascalCase = false, $symbol="_"){ 
		$string_lower = strtolower($string);
		if (!$pascalCase) 
			$string = lcfirst($string);
		$j=0;
		for($i=0;$i<strlen($string_lower);$i++){
			if( $string[$j] != $string_lower[$i] ){
				$string = str_replace($string[$j], $symbol.$string_lower[$i], $string);
				$j++;
			}
			$j++;
		}
		
		return $string; 
	} 

	public static function cast($destination, $sourceObject){
	    if (is_string($destination)) {
	        $destination = new $destination();
	    }
	    $sourceReflection = new ReflectionObject($sourceObject);
	    $destinationReflection = new ReflectionObject($destination);
	    $sourceProperties = $sourceReflection->getProperties();
	    foreach ($sourceProperties as $sourceProperty) {
	        $sourceProperty->setAccessible(true);
	        $name = $sourceProperty->getName();
	        $value = $sourceProperty->getValue($sourceObject);
	        if ($destinationReflection->hasProperty($name)) {
	            $propDest = $destinationReflection->getProperty($name);
	            $propDest->setAccessible(true);
	            $propDest->setValue($destination,$value);
	        } 
	        //else {
	        //    $destination->$name = $value;
	        //}
	    }
	    return $destination;
	}
	
}

?>